<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1>app2</h1>
  <ul>
     
  </ul>

  <script>
    // 打开一个WebSocket:
    var ws = new WebSocket('ws://localhost:9000/ws?id=bb');
    // 响应onmessage事件:
    ws.onmessage = function (msg) {
      console.log(JSON.parse(msg.data));
      var _ul = document.querySelector('ul');
      _ul.innerHTML = _ul.innerHTML+ `<li>${msg.data}</li>` 
    };
    ws.onopen = function () {
      // 给服务器发送一个字符串:
      ws.send('Hello!');
    }

  </script>
</body>

</html>